package io.geekidea.springbootplus.system.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.system.entity.SysShare;
import io.geekidea.springbootplus.system.mapper.SysShareMapper;
import io.geekidea.springbootplus.system.param.SysShare.SysSharePageParam;
import io.geekidea.springbootplus.system.service.SysShareService;
import io.geekidea.springbootplus.system.vo.SysShareQueryVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)//事务
public class SysShareServiceImpl extends BaseServiceImpl<SysShareMapper, SysShare> implements SysShareService {

    @Autowired
    private SysShareMapper sysShareMapper;

    @Override
    public boolean addSysShare(SysShare sysShare) throws Exception {
        return sysShareMapper.insert(sysShare)>0;
    }

    @Override
    public List<SysShareQueryVo> getSysShare() throws Exception {
        return sysShareMapper.selectSysShare();
    }

    @Override
    public Paging<SysShareQueryVo> getSysSharePageList(SysSharePageParam sysSharePageParam) throws Exception {
        Page<SysShare> page = new PageInfo<>(sysSharePageParam, OrderItem.desc(getLambdaColumn(SysShare::getId)));
        IPage<SysShareQueryVo> iPage = sysShareMapper.getSysSharePageList(page);
        return new Paging(iPage);
    }
}
